package com.hotelManagerSystem.controller;


import com.github.pagehelper.PageInfo;
import com.hotelManagerSystem.model.Room;
import com.hotelManagerSystem.model.RoomInfo;
import com.hotelManagerSystem.model.RoomOrder;
import com.hotelManagerSystem.model.User;
import com.hotelManagerSystem.service.IRoomInfoService;
import com.hotelManagerSystem.service.IRoomService;
import com.hotelManagerSystem.service.IUserService;
import com.hotelManagerSystem.util.PageUtil;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;


import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Cynthia
 * @since 2021-12-22
 */
@Controller
@RequestMapping("/room-info")
public class RoomInfoController {

    //注入业务接口
    @Autowired
    private IRoomInfoService iRoomInfoService;
    @Autowired
    private IRoomService iRoomService;
    @Autowired
    private IUserService iUserService;

    //查询所有房间预订信息
    @RequestMapping("/customer/list")
    public String queryAllRoomOrder(Model model,
                                    @RequestParam(required = false,defaultValue="1",value="pageNum")Integer pageNum,
                                    @RequestParam(defaultValue="8",value="pageSize")Integer pageSize){
        PageUtil.runStartPage(pageNum,pageSize);
        List<RoomInfo> roomInfos = iRoomInfoService.list();
        PageInfo pageInfo = PageUtil.getPageInfo(roomInfos);
        model.addAttribute("pageInfo",pageInfo);
        return "/system/customer/roomInfo/roomInfo-info";
    }


    /*-----查询-----房间具体信息列表-----*/
    @RequestMapping("/list")
    public String list(Model model) {
        //内置的方法list
        List<RoomInfo> roomInfoList_db=iRoomInfoService.list();
        model.addAttribute("roomInfoList_db",roomInfoList_db);
        System.out.println("===查询房间具体信息列表===list()===");
        return "system/admin/roomInfo/roomInfoList";
    }

    /*-----添加UI-----房间具体信息-----*/
    @RequestMapping("/addUI")
    public String addUI(Model model){
        System.out.println("===添加UI===addUI()===");
        return "system/admin/roomInfo/addRoomInfo";
    }

    /*-----添加-----房间具体信息-----*/
    @RequestMapping("/add")
    public String add(Model model,RoomInfo roomInfo){
        //获取数据
        System.out.println(roomInfo);
        //调用业务
        boolean b=iRoomInfoService.save(roomInfo);
        //返回roomInfoList页面
        List<RoomInfo> roomInfoList_db=iRoomInfoService.list();
        model.addAttribute("roomInfoList_db",roomInfoList_db);
        System.out.println("===添加房间具体信息===add()===");
        return "system/admin/roomInfo/roomInfoList";
    }

    /*-----删除-----通过roomInfoId删除房间具体信息-----*/
    @RequestMapping("/delete")
    public String delete(Model model,int roomInfoId){
        //获取数据
        System.out.println(roomInfoId);
        //调用业务
        boolean b=iRoomInfoService.removeById(roomInfoId);
        //返回userList页面
        List<RoomInfo> roomInfoList_db=iRoomInfoService.list();
        model.addAttribute("roomInfoList_db",roomInfoList_db);
        System.out.println("===删除房间具体信息===delete()===");
        return "system/admin/roomInfo/roomInfoList";
    }

    /*-----修改UI-----房间具体信息-----*/
    @RequestMapping("/updateUI")
    public String updateUI(Model model,int roomInfoId){
        //接收数据
        System.out.println(roomInfoId);
        //调用业务
        //通过 roomInfoId房间具体信息ID查询对应的房间具体信息
        RoomInfo roomInfo_db=iRoomInfoService.getById(roomInfoId);
        model.addAttribute("roomInfo_db",roomInfo_db);
        System.out.println("===修改UI===updateUI()===");
        //返回updateRoom页面
        return "system/admin/roomInfo/updateRoomInfo";
    }

    /*-----修改-----房间具体信息-----*/
    @RequestMapping("/update")
    public String update(Model model,RoomInfo roomInfo){
        //获取数据
        System.out.println(roomInfo);
        //调用业务进行更新
        boolean b=iRoomInfoService.saveOrUpdate(roomInfo);
        //返回roomInfoList页面
        List<RoomInfo> roomInfoList_db=iRoomInfoService.list();
        model.addAttribute("roomInfoList_db",roomInfoList_db);
        System.out.println("===修改房间具体信息===update()===");
        return "system/admin/roomInfo/roomInfoList";
    }
    /**
     * @author treasy
     * @dexscription 根据房间信息id获取房间信息记录
     */
    @RequestMapping("/getInfo")
    public String getInfoById(Model model,Integer roomInfoId,Integer roomId){
        RoomInfo roomInfo = iRoomInfoService.getById(roomInfoId);
        model.addAttribute("roomInfo",roomInfo);
        Room room = iRoomService.getById(roomId);
        model.addAttribute("room",room);
        return "/admin/roomPage/room-info";
    }
}

